#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->centralwidget->xAxis->setRange(0, 10);
       ui->centralwidget->yAxis->setRange(0, 10);


       /* 核心代码 */
       /* 底部柱状图 */
       QCPBars *barBottom = new QCPBars(ui->centralwidget->xAxis, ui->centralwidget->yAxis);
       /* 数据添加 */
       QVector<double> a(5);
       QVector<double> b(5);
       a<<1<<2<<3<<4<<5;
       b<<1<<2<<3<<4<<5;
       /* 样式改变 */
       barBottom->setBrush(QColor(10, 140, 70, 160));

       barBottom->setData(a, b);

       /* 顶部柱状图 */
       QCPBars *barTop = new QCPBars(ui->centralwidget->xAxis, ui->centralwidget->yAxis);
       QVector<double> c(5);
       QVector<double> d(5);
       c<<1<<2<<3<<4<<5;
       d<<1<<2<<1<<2<<1;
       barTop->setData(c, d);
       barTop->setBrush(QColor(10, 100, 50, 70));
       barTop->moveAbove(barBottom);
}

MainWindow::~MainWindow()
{
    delete ui;
}

